name: Sync issues internally
on:
  issues:
    types: [labeled]
  workflow_dispatch:
    inputs:
      issue_number:
        description: The issue to target
        required: true
jobs:
  internal-issue-sync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version-file: 'tools/go.mod'
      - run: make tools
      - name: Set the issue number to sync
        run: |
          if [ -n "${{ github.event.inputs.issue_number }}" ]; then
              echo "issue_number=${{ github.event.inputs.issue_number }}" >> $GITHUB_ENV
          else
              echo "issue_number=${{ github.event.issue.number }}" >> $GITHUB_ENV
          fi
      - run: go run cmd/sync-github-issue-to-jira/main.go ${{ env.issue_number }}
        if: ${{ github.event.label.name == 'triage/accepted' || github.event_name == 'workflow_dispatch' }}
        working-directory: ./tools
        env:
          GITHUB_OWNER: cloudflare
          GITHUB_REPO: terraform-provider-cloudflare
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          JIRA_HOSTNAME: ${{ secrets.JIRA_HOSTNAME }}
          JIRA_AUTH_TOKEN: ${{ secrets.JIRA_AUTH_TOKEN }}
          CF_ACCESS_CLIENT_ID: ${{ secrets.CF_ACCESS_CLIENT_ID }}
          CF_ACCESS_CLIENT_SECRET: ${{ secrets.CF_ACCESS_CLIENT_SECRET }}
